//
//  ClassifyViewController.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/2.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ClassifyViewController.h"
#import "ZJStudyClassifyModuleView.h"
#import "ZJStudyClassifyModuleViewModel.h"
#import "NetWorkingManager.h"
#import "ClassifyViewDetailController.h"
@interface ClassifyViewController ()<ZJStudyClassifyModuleViewDelegate>
/** scrollView */
@property (nonatomic, strong) UIScrollView *scrollView;
/** 数据 */
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation ClassifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self setupUI];
    [self initDataArray];
}
- (void)setupUI{
    [self.view addSubview:self.scrollView];

}

- (void)initDataArray{
    __weak typeof(self) weakSelf = self;
    [NetWorkingManager postWithUrlString:[NetWorkingURL getCategory] Parameter:nil Success:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
            weakSelf.dataArray = [[NSArray yy_modelArrayWithClass:[ZJStudyClassifyModuleViewModel class] json:object[@"FCATEGORY"]] mutableCopy];
            [weakSelf updateUIWithDataArray];
        }
        
    } Fail:^(id object) {
        
    }];


}
//根据网络请求刷新UI
- (void)updateUIWithDataArray{
    CGFloat bottom = 0.0;
    for (int i = 0; i < self.dataArray.count; i ++) {
        ZJStudyClassifyModuleView *view = [[ZJStudyClassifyModuleView alloc] initWithFrame:CGRectMake(0, bottom, self.view.width, 10)];
        view.model = self.dataArray[i];
        view.delegate = self;
        [self.scrollView addSubview:view];
        
        bottom = view.bottom;
        
        self.scrollView.contentSize = CGSizeMake(self.view.width, bottom);
    }

}


#pragma mark - ZJStudyClassifyModuleViewDelegate 协议方法
- (void)ZJStudyClassifyModuleView_ButtonClickToInfo:(ZJStudyClassifyButtonModel *)Info{
    ClassifyViewDetailController *vc = [ClassifyViewDetailController new];
    vc.classInfo = Info;
    [self.navigationController pushViewController:vc animated:YES];

}

#pragma mark - Setter


#pragma mark - Getters
- (UIScrollView *)scrollView{
    if (_scrollView == nil){
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - LP_TopHeight - 44)];
        if (self.isStudy) {
            _scrollView.height = self.view.height - 44 - LP_TopHeight - 49;
        }
        _scrollView.contentOffset = CGPointMake(0, 0);
        _scrollView.contentSize = _scrollView.size;
        
    }
    return _scrollView;
}


- (NSMutableArray *)dataArray{
    if (_dataArray == nil){
        _dataArray = [NSMutableArray array];
        
    }
    return _dataArray;
}
@end
